/*
 * Yabumi, a 2d scrolling shoot-em-up game.
 * Copyright (C) 2003 Gemma Teruaki <terugen@yabumi.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 */

#ifndef _UTIL_H_
#define _UTIL_H_

/* includes begin */ 
/* need bool */
#include <stdbool.h>
/* need SDL_Surface */
#include <SDL.h>

#ifndef _SPRITE_H_
/* need _Sprite */
#include "sprite.h"
#endif
#ifndef _HITCIRCLE_H_
/* need _Hitcircle */
#include "task/hitcircle.h"
#endif
#ifndef _PLAYER_H_
/* need _Player */
#include "task/player.h"
#endif
#ifndef _ENEMY_H_
/* need _Enemy */
#include "task/enemy.h"
#endif
#ifndef _MUSASHI_H_
/* need _Musashi */
#include "task/musashi.h"
#endif
#ifndef _MISSILE_H_
/* need _Missile */
#include "task/missile.h"
#endif
#ifndef _FLAME_H_
/* need _Flame */
#include "task/flame.h"
#endif
#ifndef _HOMING_H_
/* need _Homing */
#include "task/homing.h"
#endif
#ifndef _SMOKE_H_
/* need _Smoke */
#include "task/smoke.h"
#endif
#ifndef _EXPLOSION_H_
/* need _Homing */
#include "task/explosion.h"
#endif
#ifndef _HOMING_TAIL_H_
/* need _Homing_Tail */
#include "task/homing_tail.h"
#endif
#ifndef _ITEM_H_
/* need _Item */
#include "task/item.h"
#endif
/* includes end */

/* typedef begin */
typedef struct {
  bool up;
  bool down;
  bool left;
  bool right;
  bool space;
  bool q;
  bool z;
  bool x;
  bool c;
  bool p;
} _Key_Register;

typedef union {
  _task_item task_item;
  _Sprite Sprite;
  _Hitcircle Hitcircle;
  _Player Player;
  _Enemy Enemy;
  _Musashi Musashi;
  _Missile Missile;
  _Flame Flame;
  _Homing Homing;
  _Smoke Smoke;
  _Explosion Explosion;
  _Homing_Tail Homing_Tail;
  _Item Item;
} _item_data;

typedef struct tlist_item {
  _item_data data;
  struct tlist_item *prev;
  struct tlist_item *next;
} _list_item;

typedef struct {
  _list_item *prev;
  _list_item *next;
} _list_header;
/* typedef end */

/* constants begin */
/* SDL_Delay interval */
#define INTERVAL 30
#define RM_PI (M_PI / 180.0)
/* constants end */

/* Prototypes from the util.c file. */
void *pmalloc(size_t BlockSize);
void pfree(void *BlockAddr);
void Create_list(_list_header *header);
void Free_list(_list_header *header);
void Add_item_last(_list_header *header, _list_item *item);
void Kill_item(_list_header *header, _list_item *item);
void LoopWait();
void Read_Event();
void cap_angle(int *angle);
int distance(int x1, int y1, int x2, int y2);
double atan3(int x, int y);
int ifclockwise(int s_angle,int t_angle);
void int_wrap(int *value);
SDL_Surface* crop(SDL_Surface *s, SDL_Rect *src);
SDL_Surface *rotate(SDL_Surface *s, float ang);
#endif
